package org.chengn.level_middle.context2171;

import java.util.Arrays;

/**
 * @Title: Context2171
 * @Author ChengN
 * @Package org.chengn.level_middle.context2171
 * @Date 2024/1/18 1:20
 * @description: 拿出最少数目的魔法豆
 */
public class Context2171Simple {
    public long minimumRemoval(int[] beans) {
        Arrays.sort(beans);
        long total = 0L;
        for (int i = 0; i < beans.length; ++i) {
            total += beans[i];
        }

        long res = Long.MAX_VALUE;
        for (int i = 0; i < beans.length; ++i) {
            res = Math.min(res, total - (beans.length - i) * (long)beans[i]);
        }


        return res;
    }
}
